package cn.edu.scau.cmi.linzhanyi.singleton;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class Controller {
	
    private Chairman chairman ;
    
    @FXML
    private TextArea label;
    @FXML
    private TextField text;
    
    @FXML
    public void createChairman(ActionEvent event){
       if(Chairman.createInstance("江泽民")){
           label.setText("创建成功！！！");
       }
       else {
           label.setText("对象已经存在！！！");
       }

    }
    @FXML
    public void getChairman(ActionEvent event){
        chairman = Chairman.getInstance();
        if(chairman!=null){
            label.setText("对象hashcode："+chairman.hashCode()+"\n主席："+chairman.getName()+"\n他说："+chairman.excuteOfDuty());

        }
        else {
            label.setText("对象还未创建！！！");
        }
    }
    public void creatMultipleton() {
    	if (text.getText()!=null) 
    		if (Multipleton.addList(text.getText())) {
    			label.setText("添加"+text.getText()+"成功");
			}
    		else {
    			label.setText("添加"+text.getText()+"失败，已经超过10个多例对象");
			}
    	text.setText(null);
    		
    	
    }
    public void getMultipleton() {
    	String info = "多例人员：\n";
    	if(Multipleton.getList()!=null&&!Multipleton.getList().isEmpty())
    	for (Multipleton multipleton : Multipleton.getList()) {
			info+=multipleton.getName()+"\n";
		}
    	label.setText(info);
		
	}
}
